Open
Conversation
WoWaster
requested changes
Dec 12, 2025
Comment on lines
+40
to
+43
| void deleteList(List* list) | ||
| { | ||
| free(list); | ||
| } |
Collaborator
There was a problem hiding this comment.
Оптимистично. А вдруг инициализировали и решили удалить? Давайте всё-таки честно попробуем удалить элементы.
| return value; | ||
| } | ||
|
|
||
| index = index < 0 ? (index % list->size + list->size) : (index % list->size); |
Collaborator
There was a problem hiding this comment.
Прикольно, но вообще, наверное, логично сделать индексы только положительными
| // Deletes element with taken index. Changes index starting pointer on the next element after deleted. | ||
| // Takes pointer on the list and index of the element. | ||
| // Returns 0. If the element is the last returns element. | ||
| int deleteElement(List* list, int index); |
Collaborator
There was a problem hiding this comment.
Наверное, чуть красивее было бы сделать так:
Suggested change
| int deleteElement(List* list, int index); | |
| bool deleteElement(List* list, int index, int* out); |
Если вернулось true, то удалили последний элемент и записали в out, в ином случае out не трогать.
И в целом, по большому счёту, 0 допустим только потому что Вы воинов нумеруете от 1, а не от 0.
| int main() | ||
| { | ||
| int peopleCount, everyM; | ||
| printf("Enter people count and after how many people we kill human (Каждый k+1-ый будет убит) (separated by space): "); |
|
|
||
| int main() | ||
| { | ||
| int peopleCount, everyM; |
|
|
||
| List* people = createList(peopleCount); | ||
| int humanNumber = 0; | ||
| for (; !humanNumber; humanNumber = deleteElement(people, everyM)) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add